package Spring5.第二章.demo2_4_原型模式.浅克隆;

import java.util.ArrayList;
import java.util.List;

public class PrototypeTest {
    public static void main(String[] args) {
        // 创建一个具体的需要克隆对象
        ContcretePrototypeA contcretePrototypeA = new ContcretePrototypeA();
        // 填充属性
        contcretePrototypeA.setAge(18);
        contcretePrototypeA.setName("prototype");
        List<String> hobbies = new ArrayList<>();
        hobbies.add("qwe");
        contcretePrototypeA.setHobbies(hobbies);
        System.out.println(contcretePrototypeA);

        // 创建Client对象，开始克隆
        Client client = new Client(contcretePrototypeA);
        ContcretePrototypeA contcretePrototypeAClone = (ContcretePrototypeA) client.startClone(contcretePrototypeA);

        System.out.println("克隆对象中引用的地址：" + contcretePrototypeAClone.getHobbies());
        System.out.println("原对象中引用的地址：" + contcretePrototypeA.getHobbies());
        System.out.println("对象地址比较：" + (contcretePrototypeAClone.getHobbies() == contcretePrototypeA.getHobbies()));
    }
}
